package com.tianpengtech.admin.taskscreenshot;
import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Model;
import com.tianpengtech.admin.AbstractAdminController;
import com.tianpengtech.admin.InitInterceptor;
import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.common.model.fair.Fair;
import com.tianpengtech.common.model.task.Task;
import com.tianpengtech.common.model.task.TaskWh;
import com.tianpengtech.common.model.taskscreenshot.TaskScreenShot;

import net.sf.ehcache.constructs.nonstop.TaskNotSubmittedTimeoutException;

/**
* 路由配置地址：add("/admin/taskscreenshot", TaskScreenShotAdminController.class, "/admin/taskscreenshot");
* 数据库映射地址：arp.addMapping(TaskScreenShot.dao.tableName(),TaskScreenShot.class);
*/
@Before(InitInterceptor.class)
public class TaskScreenShotAdminController extends AbstractAdminController{

	@Override
	protected void config() {
		this.clazz=TaskScreenShot.class;
		this.service=new TaskScreenShotAdminServiceImpl();
	}

	@Override
	public void beforeAdd() {

	}

	@Override
	public void beforeAdd(Model< ? > model) throws ValidateException {

	}

	@Override
	public void beforeQueryById(Model<?> model, int id) {

	}

	@Override
	public void beforeUpdate(Model< ? > model) throws ValidateException {

	}

	@Override
	public void beforeDelete(Model< ? > model) {

	}

	@Override
	public void parsePageRecord(Object results) {
		TaskScreenShot shot = (TaskScreenShot)results;
		
		Task task = Task.dao.findById(shot.getInt(TaskScreenShot.TASK_ID));
		
		
		
		String sql="select * from "+TaskWh.dao.tableName()+" where task_id=? and wh_id=? limit 1";
		
		TaskWh taskWh = TaskWh.dao.findFirst(sql,shot.getInt(TaskScreenShot.TASK_ID),shot.getInt(TaskScreenShot.FAIR_ID));
		if(task!=null){
			shot.put("task_title", task.getStr(Task.TASK_TITLE));
		}
		
		if(taskWh!=null){
			String status =  (taskWh.getInt(TaskWh.STATUS)==Task.STATUS_COMPLETED)?"审核成功":"等待审核";
			shot.put("status",status);
		}else{
			shot.put("status","");
		}
		
		Fair fair = Fair.dao.findById(shot.getInt(TaskScreenShot.FAIR_ID));
		if(fair!=null){
			shot.put("fair_nickname",fair.getStr(Fair.NICK_NAME));
		}
		shot.set(TaskScreenShot.TYPE,shot.type());
		
	}
}

	